/**
 * 获取监听事件的回调函数类型
 * @author  韦胜健
 * @date    2021/3/9 18:13
 */
type EventListener<EmitsValue> = EmitsValue extends (...args: any[]) => any ? Parameters<EmitsValue> : never

/**
 * designComponent中emits对象类型
 * @author  韦胜健
 * @date    2021/3/9 18:12
 */
export type ObjectEmitOptions = Record<string, (...args: any[]) => boolean>

/**
 * Event对象类型
 * @author  韦胜健
 * @date    2021/3/9 18:13
 */
export type ComponentEvent<Emit> = {
    emit: { [key in keyof Emit]: (...args: EventListener<Emit[key]>) => void },
    on: { [key in keyof Emit]: (cb: (...args: EventListener<Emit[key]>) => void) => void },
    once: { [key in keyof Emit]: (cb: (...args: EventListener<Emit[key]>) => void) => void },
    off: { [key in keyof Emit]: (cb: (...args: EventListener<Emit[key]>) => void) => void },
}

/**
 * emits转化成props的对象类型
 * @author  韦胜健
 * @date    2021/3/9 18:13
 */
export type EmitToProp<E extends Record<string, (...args: any[]) => any>> =
    ('onUpdateModelValue' extends keyof E ? { onChange?: (...args: Parameters<E['onUpdateModelValue']>) => void } : {}) &
    {
        [k in keyof E]?: E[k] extends ((...args: any[]) => any) ? (...args: Parameters<E[k]>) => void : E[k]
    };